package com.wpw.dream.future;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class FutureTest {

	public static void main(String[] args) {
		
		ExecutorService executor = Executors.newCachedThreadPool();
		Future<String> future = executor.submit(new Callable<String>() {
			
			public String call() {
				try {
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				return "future处理结果";
			}});
		String a = "做我自己的事情...";
		System.out.println(a);
		while(true) {
			if (future.isDone()) {
				String res = null;
				try {
					res = future.get();
					a = a + res;
				} catch (InterruptedException e) {
					e.printStackTrace();
				} catch (ExecutionException e) {
					e.printStackTrace();
				}
				break;
			}
		}
		System.out.println(a);
		executor.shutdown();
		
	}
	

}
